package com.nbgroup.controller;


import com.nbgroup.pojo.User;
import com.nbgroup.pojo.common.PageResult;
import com.nbgroup.pojo.common.Result;
import com.nbgroup.pojo.dto.UserDTO;
import com.nbgroup.pojo.vo.LogoutVO;
import com.nbgroup.pojo.vo.RoleVo;
import com.nbgroup.pojo.vo.UserVo;
import com.nbgroup.service.SystemService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
public class SystemController {

    @Autowired
    private SystemService systemService;

    /**
     * 查询用户
     */
    @GetMapping("/system/user/list")
    public PageResult queryUser(UserDTO dto) {
        PageResult list=systemService.queryUser(dto);
        return list;
    }

    /**
     *查询角色
     */
    @GetMapping("/system/user/")
    public RoleVo queryRole(){
        return systemService.queryAllRole();
    }

    /**
     * 添加用户
     */
    @PostMapping("/system/user")
    public Result addUser(@RequestBody User user){
        systemService.addUser(user);
        return Result.success();
    }

    /**
     * 根据id查询用户
     */
    @GetMapping ("system/user/{id}")
    public UserVo updateUser(@PathVariable Integer id){
        UserVo user=systemService.genInfoUser(id);
        return user;
    }

    /**
     * 修改用户
     */
    @PutMapping("/system/user")
    public Result updateUser(@RequestBody User user){
        systemService.updateUser(user);
        return Result.success();
    }

    /**
     * 删除用户
     */
    @DeleteMapping("/system/user/{id}")
    public Result deleteUser(@PathVariable Integer id){
        systemService.deleteUser(id);
        return Result.success();
    }

    /**
     * 重置密码
     */
    @PutMapping("/system/user/resetPwd")
    public Result resetPwd(@RequestBody User user){
        log.info("重置密码,user:{}",user);
        systemService.resetPwd(user);
        return Result.success();
    }

    /**
     *
     */
    @GetMapping("/system/config/configKey/sys.user.initPassword")
    public LogoutVO initPassword(){
        return new LogoutVO("123456",200);
    }

    /**
     * 修改状态
     */
    @PutMapping("/system/user/changeStatus")
    public Result changeStatus(@RequestBody User user){
        systemService.updateUser(user);
        return Result.success();
    }
    @GetMapping("/system/user/export")
    @ApiOperation("用户数据导出")
    public Result userExport(UserDTO userDTO){
        systemService.userExport(userDTO);
        return Result.success();
    }
}
